home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Clicks, not! ƒ / Clicks, not!.a < prev   
Text File  |  1992-06-18  |  4KB  |  156 lines

  1. ;---------------------------------------------------------------------------------
  2. ;
  3. ;    File:        Clicks, not!.a
  4. ;
  5. ;    Contains:    A hack to find the SndWatch VBL in the queue which turns the
  6. ;                ASC on and off on the PowerBooks.  This makes a clicking noise
  7. ;                and we hate that, so we remove the VBL task entirely.
  8. ;
  9. ;    Written by:    Jim Reekes
  10. ;
  11. ;    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  12. ;
  13. ;    Change History (most recent first):
  14. ;
  15. ;
  16. ;    Notes:
  17. ;
  18. ;---------------------------------------------------------------------------------
  19.  
  20.                 include    'SysEqu.a'
  21.                 include    'SysErr.a'
  22.                 include    'ToolEqu.a'
  23.                 include    'Traps.a'
  24.  
  25.  
  26. ;---------------------------------------------------------------------------------
  27. ;    equates
  28. ;---------------------------------------------------------------------------------
  29.  
  30. true            equ        1
  31. false            equ        0
  32.  
  33.  
  34. SndWFreq        equ        60*10                ;Sound watch VBL is called very 10 seconds
  35. SwVBLTask        equ        $90
  36. soundRead        equ        $98                   ;Power Manager parameter block - Sound power state
  37.  
  38.  
  39. DEBUG            equ        true
  40.  
  41.  
  42. ;---------------------------------------------------------------------------------
  43. ;    macros
  44. ;---------------------------------------------------------------------------------
  45.  
  46. ;debugging symbol placed into the code for Macsbug to show us the routine name
  47.  
  48.                 macro
  49.                 DbgInfo        &routineName=&SysMod,&size=0
  50.                 lclc        &name, &oldString
  51.         
  52.                 IF DEBUG THEN
  53.                     if &routineName[1:1] = '''' then
  54.                         &name: setc &eval(&routineName)
  55.                     else
  56.                         &name: setc &routineName
  57.                     endif
  58.         
  59.                     &oldString: setc &setting('string')
  60.                     rts                                    ;need a fake rts for MacsBug
  61.                     string asis
  62.                     if &len(&name) < 32 then
  63.                         dc.b &len(&name)+$80,'&name'
  64.                     else
  65.                         dc.b $80,&len(&name),'&name'
  66.                     endif
  67.                     string &oldString
  68.                     align
  69.                     dc.w &size
  70.                 endif
  71.                 endm
  72.  
  73.  
  74. ;---------------------------------------------------------------------------------
  75. ;    The main entry point.
  76. ;---------------------------------------------------------------------------------
  77.  
  78. StartINIT        MAIN
  79.  
  80.                 jsr        DoVBLKiller
  81.                 rts                                    ;bye bye
  82.  
  83.                 DbgInfo    StartINIT                    ;this name will appear in the debugger
  84.  
  85. ;---------------------------------------------------------------------------------
  86. ;    Target code we're looking for in the VBL task
  87. ;    This is the source code that appears inside of the Power Manager that
  88. ;    I want to find and destroy.
  89. ;---------------------------------------------------------------------------------
  90.  
  91. StartTargetCode        equ *                        ;marker to calculate the size of this code
  92.  
  93. SndWatch        MOVE.L    PmgrBase,A2
  94.                 LEA        SwVBLTask(A2),A0
  95.                 MOVE.W    #SndWFreq,vblCount(A0)
  96.  
  97.                 SUB.W    #4,SP
  98.                 MOVE.L    SP,A0
  99.                 MOVE.W    #SoundRead,D0
  100.  
  101. BytesOfTargetCode    equ *-StartTargetCode        ;size of the target code
  102.  
  103.                 DbgInfo    SndWatch                ;this name will appear in the debugger
  104.  
  105. ;---------------------------------------------------------------------------------
  106. ;    Find the bogus SndWatch VBL in the queue and remove it
  107. ;---------------------------------------------------------------------------------
  108.  
  109. SaveKillerRegs    reg        d0/a0-a2                ;those that we will use we preserve
  110.  
  111. DoVBLKiller
  112.                 movem.l    SaveKillerRegs,-(sp)
  113.                 move.l    VBLQueue+qHead,a0        ;point into the VBL queue
  114.  
  115.                 ;We want to confirm that this is the right routine that needs modified.
  116.                 ;This is done with a small loop. The C code below shows the idea.
  117.  
  118.                 ;for (count = (BytesOfTargetCode/2)-1;count >= 0;--count)
  119.                 ;    {
  120.                 ;    if (sourceWordPtr++ == destWordPtr++)
  121.                 ;        codeMatches = true;
  122.                 ;    else
  123.                 ;        codeMatches = false;
  124.                 ;    }
  125.                 ;if (codeMatches)
  126.                 ;    RemoveVBL();
  127.  
  128. NextVBL
  129.                 move.l    vblAddr(a0),a1
  130.                 lea        StartTargetCode,a2                ;point to are test code
  131.                 move.w    #(BytesOfTargetCode/2)-1,d0        ;count is DIV 2 for number of words
  132. CompareLoop
  133.                 ;a1 points at the original code in the VBL task
  134.                 ;a2 points at our test code for comparing against
  135.                 ;d0 is the loop counter, in the number of words to compare
  136.  
  137.                 cmp.w    (a1)+,(a2)+
  138.                 dbne    d0,CompareLoop
  139.                 beq.s    FoundVBL
  140.  
  141.                 move.l    vblink(a0),a0
  142.                 cmp.l    #0,a0
  143.                 beq.s    ExitKiller                    ;no more VBLs in the queue
  144.  
  145.                 bra.s    NextVBL
  146.  
  147. FoundVBL        _VRemove
  148.  
  149. ExitKiller
  150.                 movem.l    (sp)+,SaveKillerRegs
  151.                 rts
  152.                 DbgInfo    DoVBLKiller                    ;this name will appear in the debugger
  153.  
  154.  
  155.     end        ;of source file
  156.